using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace Common.Utilities
{
    /// <summary>
    /// 
    /// </summary>
    public class SortableRectangle : IComparable
    {
        private RectangleF _Rect;
        /// <summary></summary>
        public RectangleF Rect
        {
            get { return _Rect; }
            set { _Rect = value; }
        }
        /// <summary></summary>
        public SortableRectangle(RectangleF rect)
        {
            this._Rect = rect;
        }
        /// <summary></summary>
        public int CompareTo(object obj)
        {
            if (obj.GetType() == typeof(SortableRectangle))
            {
                SortableRectangle otherSortableRect = (SortableRectangle)obj;
                RectangleF otherRect = otherSortableRect.Rect;
                if (Math.Abs(this.Rect.Y - otherRect.Y) < 8)
                {
                    if (Math.Abs(this.Rect.X - otherRect.X) < 8)
                    {
                        return 0;
                    }
                    else
                    {
                        return this.Rect.X.CompareTo(otherRect.X);
                    }
                }
                else
                {
                    return this.Rect.Y.CompareTo(otherRect.Y);
                }
            }
            else
                throw new Exception("Invalid type to compare");
        }
    }
}
